package in.animeshpathak.androvita;

import in.animeshpathak.androvita.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;

public class AndroVitaActivity extends Activity implements OnTouchListener {
    
	private static final String TOUCHDEMO_TAG = "AP - TouchDemo";
	TouchView myTouchView;
	TextView myStatusTextView;

    	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        
        myTouchView = (TouchView) findViewById(R.id.myTouchView);
        myTouchView.setOnTouchListener(this);
        
        myStatusTextView = (TextView) findViewById(R.id.statusTextView);
        
    }

    
    // From onTouchListener
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// Doing nothing no. But later... something
		Log.d(TOUCHDEMO_TAG, "Touched!");
		
		float x, rawX, precisionX;
		float y, rawY, precisionY;
		
		x = event.getX();
		rawX = event.getRawX();
		precisionX = event.getXPrecision();

		y = event.getY();
		rawY = event.getRawY();
		precisionY = event.getYPrecision();
		
		String infoText = "(X,RawX,PrecisionX) = (" + x +"," + rawX + "," + precisionX +");" +
				"(Y,RawY,PrecisionY) = (" + y +"," + rawY + "," + precisionY +")";

		String basicCoordinateText = "("+ x +",\t" + y + ")";
		
		//pass event to the touchView. Return whatever it returns.
		switch(event.getAction()){
			case MotionEvent.ACTION_DOWN:
				Log.d(TOUCHDEMO_TAG,"Down " + infoText);
				myStatusTextView.setText(basicCoordinateText);
				return myTouchView.touchDown(x, y);
			case MotionEvent.ACTION_MOVE:
				Log.d(TOUCHDEMO_TAG, "Moved!" + infoText);
				myStatusTextView.setText(basicCoordinateText);
				return myTouchView.touchMove(x, y);
			case MotionEvent.ACTION_UP:
				Log.d(TOUCHDEMO_TAG, "Up!" + infoText);
				myStatusTextView.setText(basicCoordinateText);
				return myTouchView.touchUp(x,y);
		}
		
		//nothing we are interested in, maybe the others will want?
		return false;
	}
}